"use strict"

const moment = require('moment')

module.exports = (app) => {
    const { STRING, DATE, DECIMAL, INTEGER, TEXT } = app.Sequelize
    const GoodsSku = app.model.define('goods_sku', {
        id: {
            type: INTEGER,
            autoIncrement: true,
            primaryKey: true,
        },
        goods_id: {
            type: INTEGER,
            alloeNull: false
        },
        attribute_specs: {
            type: TEXT,
            alloeNull: false,
            get() {
                return JSON.parse(this.getDataValue('attribute_specs'))
            }
        },
        sales_price: {
            type: DECIMAL,
            alloeNull: false,
            set(val) {
                this.setDataValue('sales_price', val ? val: 0)
            }
        },
        price: {
            type: DECIMAL,
            alloeNull: false,
            set(val) {
                this.setDataValue('price', val ? val: 0)
            }
        },
        inventory: {
            type: STRING,
            alloeNull: false
        },
        create_time: {
            type: DATE,
            alloeNull: false,
            get() {
                return moment(this.getDataValue('create_time')).format('YYYY-MM-DD')
            }
        }
    });

    return GoodsSku
}